//
//  SplashViewController.m
//  Megatlon
//
//  Created by Leandro Milmanda on 5/26/12.
//  Copyright 2012 www.lemil.com.ar. All rights reserved.
//

#import "SplashViewController.h"
#import "SucursalesDao.h"

@implementation SplashViewController

@synthesize activityIndicator, delegate;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
    
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    //
    [activityIndicator startAnimating];
    activityIndicator.hidden = NO;
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
       
        dispatch_async( dispatch_get_main_queue(), ^{
        
            //
            SucursalesDao *dao = [SucursalesDao instance];
            [dao load];
        
            [NSThread sleepForTimeInterval: 2 ];
        
            //
            [activityIndicator stopAnimating];
            activityIndicator.hidden = YES;
        
            BOOL success = [dao isLoaded]; 
        
            [[self delegate] splashViewLoaded:success];
            
        });
    });
    
    
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
